package com.dlwx.parttimetalent.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.bean.MsgBean;
import com.dlwx.parttimetalent.comm.Constant;

/**
 * Created by Administrator on 2017/11/21.
 */

public class MsgAdapter extends ListBaseAdapter<MsgBean.BodyBean> {
    private  Context context;
    private int type;
    public MsgAdapter(Context context, int type) {
        super(context);
        this.context=context;
        this.type=type;
    }



    @Override
    public int getLayoutId() {
        return R.layout.item_msg;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, final int position) {
        MsgBean.BodyBean bean = getDataList().get(position);
        TextView tvTitle=holder.getView(R.id.tv_title);
        TextView tvTime=holder.getView(R.id.tv_time);
        TextView tvContent=holder.getView(R.id.tv_content);
        ImageView imageView=holder.getView(R.id.image_header);
        Button deleteBtn=holder.getView(R.id.btnDelete);
        tvTime.setText(bean.getMsgtime());
        tvContent.setText(bean.getMsginfo());
        deleteBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnSwipeListener.onDel(position);
            }
        });
        switch (type){
            case Constant.MSG_SYS:
                imageView.setImageResource(R.mipmap.icon_xxxitong);
                tvTitle.setText("系统消息");
                break;
            case Constant.MSG_ORDER:
                imageView.setImageResource(R.mipmap.icon_xxdingdan);
                tvTitle.setText("订单消息");
                break;
            case Constant.MSG_TRADE:
                imageView.setImageResource(R.mipmap.icon_xxjiaoyi);
                tvTitle.setText("交易消息");
                break;
        }
    }

    /**
     * 和Activity通信的接口
     */
    public interface onSwipeListener {
        void onDel(int pos);

        void onTop(int pos);
    }

    private WorkExperienceAdapter.onSwipeListener mOnSwipeListener;

    public void setOnDelListener(WorkExperienceAdapter.onSwipeListener mOnDelListener) {
        this.mOnSwipeListener = mOnDelListener;
    }
}
